package tool

import (
	"fmt"
	"encoding/json"
	"strconv"
	"reflect"
)

func Pic(hint string, v interface{}){
	fmt.Println(hint+"-------------------------------"+hint)
	fmt.Println(v)
	fmt.Println(hint+"-------------------------------"+hint)
}


func  Tojson( v interface{} ) string {

   jsonstr,_ := json.Marshal(v)
   return string(jsonstr)
}

func IntoFloat(num int ) float64{

	intstring := strconv.Itoa(num) 
	num64,err := strconv.ParseFloat(intstring,64)
	if(err!=nil){
		return 0.00
	}else{
		return num64
	}
} 

func XtoInt(num interface{}) int {
	numtype := reflect.TypeOf(num)
	
	

	if(numtype.Name() == "string"){
		stringnum := num.(string);
		re,_ := strconv.Atoi(stringnum)
		return re
	}

	if(numtype.Name() =="float64"){

		Pic("type","float")

		Pic("typenum",num)
	 
		float64num := num.(float64) 
		numstring := strconv.FormatFloat(float64num,'E',-1,64)

		//intnum := num.(int)

		//fmt.Println(intnum)

		Pic("typenumstring",numstring)
		re,_ := strconv.Atoi(numstring)
		
		Pic("type",re)

		return re
	}

	return 0
}